﻿using Luna.Data.Budget;

namespace Luna.Model.Budget
{
    internal class Line : LunaEntity<ILineData>, ILine
    {
        public Line()
            : base()
        {
        }

        public Line(Line P_Base)
            : base(P_Base)
        {
        }

        public Line(ILineData P_Data)
            : base(P_Data)
        {
        }

        public decimal? Amount
        {
            get { return Data.Amount; }
        }

        public IBudget Budget
        {
            get { return GetEntity(ServicesResolver.Get<IBudgetService>().Budgets, Data.BudgetID); }
        }

        public ICategory Category
        {
            get { return GetEntity(ServicesResolver.Get<IBudgetService>().Categories, Data.CategoryID); }
        }

        public string Code
        {
            get { return Data.Code; }
        }

        public string Description
        {
            get { return Data.Description; }
        }

        public string Name
        {
            get { return Data.Name; }
        }

        public ILine Parent
        {
            get
            {
                if (Data.ParentID.HasValue)
                {
                    var L_Data = DataResolver.Get<IBudgetProvider>().LineGet(Data.ParentID.Value);
                    if (L_Data != null)
                    {
                        return new Line(L_Data);
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
        }
    }
}